package com.ms.service.module.zone.command;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

import com.ms.service.module.zone.action.DebugCommandAction;

/**
 * 方便查找命令
 * @author Helo Yi
 *
 */
public class HelpCommand extends BasicDebugCommand {

	@Override
	public String execute() {
		String name = getParam(1);
		if (name == null) {
			name = "";
		}

		if (!name.equals(getName()) && DebugCommandAction.gmCommandDescs.containsKey(name)) {
			String desc = DebugCommandAction.gmCommandDescs.get(name);
			return "cmd : " + name + ",  desc : " + desc;
		} else {
			List<String> list = new ArrayList<String>(DebugCommandAction.gmCommandDescs.keySet());
			Collections.sort(list);

			String result = "";
			for (String n : list) {
				result += n + ": " + DebugCommandAction.gmCommandShortDescs.get(n) + "\n";
			}
			return result;
		}
	}

	@Override
	public String getName() {
		return "help";
	}

	@Override
	public String getDescription() {
		return "[command name]";
	}

	/*
	 * @see com.ms.service.module.zone.command.BasicDebugCommand#getShortDescription()
	 */
	@Override
	public String getShortDescription() {
		
		return "show command list.";
	}

}
